package org.fujene.memoryblock.invert;

import java.nio.ByteBuffer;
import java.util.HashSet;
import org.fujene.memman.DeleteFilter;

public class OptimizerInvertIndexBlock extends InvertIndexBlock{
	public OptimizerInvertIndexBlock(ByteBuffer existingBody){
		super(existingBody);
	}

	// Find whole memory space and to get IDs whose flag filters
	public HashSet<Long> pickIDbyFlag(DeleteFilter filter){
		HashSet<Long> pickedIDs = new HashSet<Long>(1000);
		int ptr = 0;
		int flagval = -1;

		for(int i = 0; i < option[OPT_LEN]; i++){
			ptr += NEWEST;
			for(int j = 0; j < option[OPT_PERTERM]; j++){
				ptr += option[OPT_BOOLARR] + (INT * filter.deleteKeyType());
				flagval = getInt(ptr, INT);
				ptr += (INT * (option[OPT_MULFLAG] - filter.deleteKeyType()));
				if(filter.filter(flagval)){
					pickedIDs.add(getLong(ptr, LONG));
				}
				ptr += LONG;
			}
		}

		return pickedIDs;
	}
}
